<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="角色ID">
              <a-input placeholder="请输入"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="状态">
              <a-select placeholder="请选择" default-value="0">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">正常</a-select-option>
                <a-select-option value="2">禁用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary">查询</a-button>
              <a-button style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <s-table
      ref="table"
      size="default"
      :columns="columns"
      :data="loadData"
    >
      <div
        slot="expandedRowRender"
        slot-scope="record"
        style="margin: 0">
        <a-row
          :gutter="24"
          :style="{ marginBottom: '12px' }">
          <a-col :span="12" v-for="(role, index) in record.permissions" :key="index" :style="{ marginBottom: '12px' }">
            <a-col :span="4">
              <span>{{ role.permissionName }}：</span>
            </a-col>
            <a-col :span="20" v-if="role.actionEntitySet.length > 0">
              <a-tag color="cyan" v-for="(action, k) in role.actionEntitySet" :key="k">{{ action.describe }}</a-tag>
            </a-col>
            <a-col :span="20" v-else>-</a-col>
          </a-col>
        </a-row>
      </div>
      <span slot="action" slot-scope="text, record">
        <a @click="$refs.modal.edit(record)">编辑</a>
        <a-divider type="vertical" />
        <a-dropdown>
          <a class="ant-dropdown-link">
            更多 <a-icon type="down" />
          </a>
          <a-menu slot="overlay">
            <a-menu-item>
              <a href="javascript:;">详情</a>
            </a-menu-item>
            <a-menu-item>
              <a href="javascript:;">禁用</a>
            </a-menu-item>
            <a-menu-item>
              <a href="javascript:;">删除</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
    </s-table>

    <selectBank ref="modal" @ok="handleOk"></selectBank>

  </a-card>
</template>

<script>
  import STable from '@/components/table/'
  import selectBank from './modules/selectBank'

  export default {
    name: "TableList",
    components: {
      STable,
      selectBank
    },
    data () {
      return {
        description: '列表使用场景：后台管理中的权限管理以及角色管理，可用于基于 RBAC 设计的角色权限控制，颗粒度细到每一个操作类型。',

        visible: false,

        form: null,
        mdl: {},

        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'主键',
          //   align:"center",
          //   dataIndex: 'guid'
          // },
          {
            title:'标段编号',
            align:"center",
            dataIndex: 'bidSectionCode'
          },
          {
            title:'标段名称',
            align:"center",
            dataIndex: 'bidSectionName'
          },
          {
            title:'招标项目编号',
            align:"center",
            dataIndex: 'tenderProjectCode'
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'projectName'
          },
          {
            title:'公共资源交易类型',
            align:"center",
            dataIndex: 'publicResourceType'
          },
          {
            title:'主体建设单位',
            align:"center",
            dataIndex: 'mainConstructionUnit'
          },
          {
            title:'组织机构代码/统一社会信用代码',
            align:"center",
            dataIndex: 'organNo'
          },
          // {
          //   title:'招标项目主键',
          //   align:"center",
          //   dataIndex: 'tenderProjectGuid'
          // },
          {
            title:'标段分类',
            align:"center",
            dataIndex: 'sectionType'
          },
          {
            title:'标段合同估算价（万元）',
            align:"center",
            dataIndex: 'contractPrice'
          },
          {
            title:'投标保证金金额（万元）',
            align:"center",
            dataIndex: 'bidBond'
          },
          {
            title:'投标保证金缴纳方式',
            align:"center",
            dataIndex: 'bondPayType'
          },
          // {
          //   title:'投标保证金账号',
          //   align:"center",
          //   dataIndex: 'bondAccount'
          // },
          // {
          //   title:'开户行',
          //   align:"center",
          //   dataIndex: 'bank'
          // },
          // {
          //   title:'户名',
          //   align:"center",
          //   dataIndex: 'accountName'
          // },
          // {
          //   title:'是否退还利息',
          //   align:"center",
          //   dataIndex: 'isBakBond'
          // },
          {
            title:'投标保证金截止时间',
            align:"center",
            dataIndex: 'bidBondEndtime'
          },
          {
            title:'入库时间',
            align:"center",
            dataIndex: 'version'
          },
          // {
          //   title:'招标内容',
          //   align:"center",
          //   dataIndex: 'tendererContent'
          // },
          // {
          //   title:'评标方式',
          //   align:"center",
          //   dataIndex: 'bidEvaluationMethod'
          // },
          // {
          //   title:'项目资质要求',
          //   align:"center",
          //   dataIndex: 'projectQualification'
          // },
          // {
          //   title:'项目经理（总监）专业',
          //   align:"center",
          //   dataIndex: 'projectManagerMajor'
          // },
          // {
          //   title:'项目经理（总监）最低资格等级',
          //   align:"center",
          //   dataIndex: 'projectManagerMinQualification'
          // },
          // {
          //   title:'工程专业类型',
          //   align:"center",
          //   dataIndex: 'engineeringMajorType'
          // },
          {
            title:'标段状态',//（1.正常、2.流标、3.暂停、4.终止）
            align:"center",
            dataIndex: 'sectionStatus'
          },
          {
            title:'行政区划代码',
            align:"center",
            dataIndex: 'areaCode'
          },
          {
            title:'交易平台编号',
            align:"center",
            dataIndex: 'jyptBh'
          },
          // {
          //   title:'逻辑删除字段',
          //   align:"center",
          //   dataIndex: 'isdeleted'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return this.$http.get('/finanTenderInfo/list', {
            params: ''
          }).then(res => {
            return res.result
          })
        },

        selectedRowKeys: [],
        selectedRows: []
      }
    },
    methods: {
      handleEdit (record) {
        this.mdl = Object.assign({}, record)

        this.mdl.permissions.forEach(permission => {
          permission.actionsOptions = permission.actionEntitySet.map(action => {
            return { label: action.describe, value: action.action, defaultCheck: action.defaultCheck }
          })
        })

        console.log(this.mdl)
        this.visible = true
      },
      handleOk () {
        // 新增/修改 成功时，重载列表
        this.$refs.table.refresh()
      },
      onChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
    },
    watch: {
      /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
    }
  }
</script>